// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_bigint_from_datetimev2_6_part1") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_bigint_from_datetimev2_6_part1_1_nullable;"
    sql "create table test_cast_to_bigint_from_datetimev2_6_part1_1_nullable(f1 int, f2 datetimev2(6)) properties('replication_num'='1');"
    sql """insert into test_cast_to_bigint_from_datetimev2_6_part1_1_nullable values (0, "0000-12-01 01:00:59.000000"),(1, "0000-12-01 01:00:59.000001"),(2, "0000-12-01 01:00:59.999999"),(3, "0000-12-01 01:01:00.000000"),(4, "0000-12-01 01:01:00.000001"),(5, "0000-12-01 01:01:00.999999"),(6, "0000-12-01 01:01:01.000000"),(7, "0000-12-01 01:01:01.000001"),(8, "0000-12-01 01:01:01.999999"),(9, "0000-12-01 01:01:59.000000"),(10, "0000-12-01 01:01:59.000001"),(11, "0000-12-01 01:01:59.999999"),(12, "0000-12-01 01:59:00.000000"),(13, "0000-12-01 01:59:00.000001"),(14, "0000-12-01 01:59:00.999999"),(15, "0000-12-01 01:59:01.000000"),(16, "0000-12-01 01:59:01.000001"),(17, "0000-12-01 01:59:01.999999"),(18, "0000-12-01 01:59:59.000000"),(19, "0000-12-01 01:59:59.000001"),
      (20, "0000-12-01 01:59:59.999999"),(21, "0000-12-01 23:00:00.000000"),(22, "0000-12-01 23:00:00.000001"),(23, "0000-12-01 23:00:00.999999"),(24, "0000-12-01 23:00:01.000000"),(25, "0000-12-01 23:00:01.000001"),(26, "0000-12-01 23:00:01.999999"),(27, "0000-12-01 23:00:59.000000"),(28, "0000-12-01 23:00:59.000001"),(29, "0000-12-01 23:00:59.999999"),(30, "0000-12-01 23:01:00.000000"),(31, "0000-12-01 23:01:00.000001"),(32, "0000-12-01 23:01:00.999999"),(33, "0000-12-01 23:01:01.000000"),(34, "0000-12-01 23:01:01.000001"),(35, "0000-12-01 23:01:01.999999"),(36, "0000-12-01 23:01:59.000000"),(37, "0000-12-01 23:01:59.000001"),(38, "0000-12-01 23:01:59.999999"),(39, "0000-12-01 23:59:00.000000"),
      (40, "0000-12-01 23:59:00.000001"),(41, "0000-12-01 23:59:00.999999"),(42, "0000-12-01 23:59:01.000000"),(43, "0000-12-01 23:59:01.000001"),(44, "0000-12-01 23:59:01.999999"),(45, "0000-12-01 23:59:59.000000"),(46, "0000-12-01 23:59:59.000001"),(47, "0000-12-01 23:59:59.999999"),(48, "0000-12-28 00:00:00.000000"),(49, "0000-12-28 00:00:00.000001"),(50, "0000-12-28 00:00:00.999999"),(51, "0000-12-28 00:00:01.000000"),(52, "0000-12-28 00:00:01.000001"),(53, "0000-12-28 00:00:01.999999"),(54, "0000-12-28 00:00:59.000000"),(55, "0000-12-28 00:00:59.000001"),(56, "0000-12-28 00:00:59.999999"),(57, "0000-12-28 00:01:00.000000"),(58, "0000-12-28 00:01:00.000001"),(59, "0000-12-28 00:01:00.999999"),
      (60, "0000-12-28 00:01:01.000000"),(61, "0000-12-28 00:01:01.000001"),(62, "0000-12-28 00:01:01.999999"),(63, "0000-12-28 00:01:59.000000"),(64, "0000-12-28 00:01:59.000001"),(65, "0000-12-28 00:01:59.999999"),(66, "0000-12-28 00:59:00.000000"),(67, "0000-12-28 00:59:00.000001"),(68, "0000-12-28 00:59:00.999999"),(69, "0000-12-28 00:59:01.000000"),(70, "0000-12-28 00:59:01.000001"),(71, "0000-12-28 00:59:01.999999"),(72, "0000-12-28 00:59:59.000000"),(73, "0000-12-28 00:59:59.000001"),(74, "0000-12-28 00:59:59.999999"),(75, "0000-12-28 01:00:00.000000"),(76, "0000-12-28 01:00:00.000001"),(77, "0000-12-28 01:00:00.999999"),(78, "0000-12-28 01:00:01.000000"),(79, "0000-12-28 01:00:01.000001"),
      (80, "0000-12-28 01:00:01.999999"),(81, "0000-12-28 01:00:59.000000"),(82, "0000-12-28 01:00:59.000001"),(83, "0000-12-28 01:00:59.999999"),(84, "0000-12-28 01:01:00.000000"),(85, "0000-12-28 01:01:00.000001"),(86, "0000-12-28 01:01:00.999999"),(87, "0000-12-28 01:01:01.000000"),(88, "0000-12-28 01:01:01.000001"),(89, "0000-12-28 01:01:01.999999"),(90, "0000-12-28 01:01:59.000000"),(91, "0000-12-28 01:01:59.000001"),(92, "0000-12-28 01:01:59.999999"),(93, "0000-12-28 01:59:00.000000"),(94, "0000-12-28 01:59:00.000001"),(95, "0000-12-28 01:59:00.999999"),(96, "0000-12-28 01:59:01.000000"),(97, "0000-12-28 01:59:01.000001"),(98, "0000-12-28 01:59:01.999999"),(99, "0000-12-28 01:59:59.000000"),
      (100, "0000-12-28 01:59:59.000001"),(101, "0000-12-28 01:59:59.999999"),(102, "0000-12-28 23:00:00.000000"),(103, "0000-12-28 23:00:00.000001"),(104, "0000-12-28 23:00:00.999999"),(105, "0000-12-28 23:00:01.000000"),(106, "0000-12-28 23:00:01.000001"),(107, "0000-12-28 23:00:01.999999"),(108, "0000-12-28 23:00:59.000000"),(109, "0000-12-28 23:00:59.000001"),(110, "0000-12-28 23:00:59.999999"),(111, "0000-12-28 23:01:00.000000"),(112, "0000-12-28 23:01:00.000001"),(113, "0000-12-28 23:01:00.999999"),(114, "0000-12-28 23:01:01.000000"),(115, "0000-12-28 23:01:01.000001"),(116, "0000-12-28 23:01:01.999999"),(117, "0000-12-28 23:01:59.000000"),(118, "0000-12-28 23:01:59.000001"),(119, "0000-12-28 23:01:59.999999"),
      (120, "0000-12-28 23:59:00.000000"),(121, "0000-12-28 23:59:00.000001"),(122, "0000-12-28 23:59:00.999999"),(123, "0000-12-28 23:59:01.000000"),(124, "0000-12-28 23:59:01.000001"),(125, "0000-12-28 23:59:01.999999"),(126, "0000-12-28 23:59:59.000000"),(127, "0000-12-28 23:59:59.000001"),(128, "0000-12-28 23:59:59.999999"),(129, "0001-01-01 00:00:00.000000"),(130, "0001-01-01 00:00:00.000001"),(131, "0001-01-01 00:00:00.999999"),(132, "0001-01-01 00:00:01.000000"),(133, "0001-01-01 00:00:01.000001"),(134, "0001-01-01 00:00:01.999999"),(135, "0001-01-01 00:00:59.000000"),(136, "0001-01-01 00:00:59.000001"),(137, "0001-01-01 00:00:59.999999"),(138, "0001-01-01 00:01:00.000000"),(139, "0001-01-01 00:01:00.000001"),
      (140, "0001-01-01 00:01:00.999999"),(141, "0001-01-01 00:01:01.000000"),(142, "0001-01-01 00:01:01.000001"),(143, "0001-01-01 00:01:01.999999"),(144, "0001-01-01 00:01:59.000000"),(145, "0001-01-01 00:01:59.000001"),(146, "0001-01-01 00:01:59.999999"),(147, "0001-01-01 00:59:00.000000"),(148, "0001-01-01 00:59:00.000001"),(149, "0001-01-01 00:59:00.999999"),(150, "0001-01-01 00:59:01.000000"),(151, "0001-01-01 00:59:01.000001"),(152, "0001-01-01 00:59:01.999999"),(153, "0001-01-01 00:59:59.000000"),(154, "0001-01-01 00:59:59.000001"),(155, "0001-01-01 00:59:59.999999"),(156, "0001-01-01 01:00:00.000000"),(157, "0001-01-01 01:00:00.000001"),(158, "0001-01-01 01:00:00.999999"),(159, "0001-01-01 01:00:01.000000"),
      (160, "0001-01-01 01:00:01.000001"),(161, "0001-01-01 01:00:01.999999"),(162, "0001-01-01 01:00:59.000000"),(163, "0001-01-01 01:00:59.000001"),(164, "0001-01-01 01:00:59.999999"),(165, "0001-01-01 01:01:00.000000"),(166, "0001-01-01 01:01:00.000001"),(167, "0001-01-01 01:01:00.999999"),(168, "0001-01-01 01:01:01.000000"),(169, "0001-01-01 01:01:01.000001"),(170, "0001-01-01 01:01:01.999999"),(171, "0001-01-01 01:01:59.000000"),(172, "0001-01-01 01:01:59.000001"),(173, "0001-01-01 01:01:59.999999"),(174, "0001-01-01 01:59:00.000000"),(175, "0001-01-01 01:59:00.000001"),(176, "0001-01-01 01:59:00.999999"),(177, "0001-01-01 01:59:01.000000"),(178, "0001-01-01 01:59:01.000001"),(179, "0001-01-01 01:59:01.999999"),
      (180, "0001-01-01 01:59:59.000000"),(181, "0001-01-01 01:59:59.000001"),(182, "0001-01-01 01:59:59.999999"),(183, "0001-01-01 23:00:00.000000"),(184, "0001-01-01 23:00:00.000001"),(185, "0001-01-01 23:00:00.999999"),(186, "0001-01-01 23:00:01.000000"),(187, "0001-01-01 23:00:01.000001"),(188, "0001-01-01 23:00:01.999999"),(189, "0001-01-01 23:00:59.000000"),(190, "0001-01-01 23:00:59.000001"),(191, "0001-01-01 23:00:59.999999"),(192, "0001-01-01 23:01:00.000000"),(193, "0001-01-01 23:01:00.000001"),(194, "0001-01-01 23:01:00.999999")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_datetimev2_6_part1_1_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_datetimev2_6_part1_1_nullable order by 1;'

    sql "drop table if exists test_cast_to_bigint_from_datetimev2_6_part1_1_not_nullable;"
    sql "create table test_cast_to_bigint_from_datetimev2_6_part1_1_not_nullable(f1 int, f2 datetimev2(6)) properties('replication_num'='1');"
    sql """insert into test_cast_to_bigint_from_datetimev2_6_part1_1_not_nullable values (0, "0000-12-01 01:00:59.000000"),(1, "0000-12-01 01:00:59.000001"),(2, "0000-12-01 01:00:59.999999"),(3, "0000-12-01 01:01:00.000000"),(4, "0000-12-01 01:01:00.000001"),(5, "0000-12-01 01:01:00.999999"),(6, "0000-12-01 01:01:01.000000"),(7, "0000-12-01 01:01:01.000001"),(8, "0000-12-01 01:01:01.999999"),(9, "0000-12-01 01:01:59.000000"),(10, "0000-12-01 01:01:59.000001"),(11, "0000-12-01 01:01:59.999999"),(12, "0000-12-01 01:59:00.000000"),(13, "0000-12-01 01:59:00.000001"),(14, "0000-12-01 01:59:00.999999"),(15, "0000-12-01 01:59:01.000000"),(16, "0000-12-01 01:59:01.000001"),(17, "0000-12-01 01:59:01.999999"),(18, "0000-12-01 01:59:59.000000"),(19, "0000-12-01 01:59:59.000001"),
      (20, "0000-12-01 01:59:59.999999"),(21, "0000-12-01 23:00:00.000000"),(22, "0000-12-01 23:00:00.000001"),(23, "0000-12-01 23:00:00.999999"),(24, "0000-12-01 23:00:01.000000"),(25, "0000-12-01 23:00:01.000001"),(26, "0000-12-01 23:00:01.999999"),(27, "0000-12-01 23:00:59.000000"),(28, "0000-12-01 23:00:59.000001"),(29, "0000-12-01 23:00:59.999999"),(30, "0000-12-01 23:01:00.000000"),(31, "0000-12-01 23:01:00.000001"),(32, "0000-12-01 23:01:00.999999"),(33, "0000-12-01 23:01:01.000000"),(34, "0000-12-01 23:01:01.000001"),(35, "0000-12-01 23:01:01.999999"),(36, "0000-12-01 23:01:59.000000"),(37, "0000-12-01 23:01:59.000001"),(38, "0000-12-01 23:01:59.999999"),(39, "0000-12-01 23:59:00.000000"),
      (40, "0000-12-01 23:59:00.000001"),(41, "0000-12-01 23:59:00.999999"),(42, "0000-12-01 23:59:01.000000"),(43, "0000-12-01 23:59:01.000001"),(44, "0000-12-01 23:59:01.999999"),(45, "0000-12-01 23:59:59.000000"),(46, "0000-12-01 23:59:59.000001"),(47, "0000-12-01 23:59:59.999999"),(48, "0000-12-28 00:00:00.000000"),(49, "0000-12-28 00:00:00.000001"),(50, "0000-12-28 00:00:00.999999"),(51, "0000-12-28 00:00:01.000000"),(52, "0000-12-28 00:00:01.000001"),(53, "0000-12-28 00:00:01.999999"),(54, "0000-12-28 00:00:59.000000"),(55, "0000-12-28 00:00:59.000001"),(56, "0000-12-28 00:00:59.999999"),(57, "0000-12-28 00:01:00.000000"),(58, "0000-12-28 00:01:00.000001"),(59, "0000-12-28 00:01:00.999999"),
      (60, "0000-12-28 00:01:01.000000"),(61, "0000-12-28 00:01:01.000001"),(62, "0000-12-28 00:01:01.999999"),(63, "0000-12-28 00:01:59.000000"),(64, "0000-12-28 00:01:59.000001"),(65, "0000-12-28 00:01:59.999999"),(66, "0000-12-28 00:59:00.000000"),(67, "0000-12-28 00:59:00.000001"),(68, "0000-12-28 00:59:00.999999"),(69, "0000-12-28 00:59:01.000000"),(70, "0000-12-28 00:59:01.000001"),(71, "0000-12-28 00:59:01.999999"),(72, "0000-12-28 00:59:59.000000"),(73, "0000-12-28 00:59:59.000001"),(74, "0000-12-28 00:59:59.999999"),(75, "0000-12-28 01:00:00.000000"),(76, "0000-12-28 01:00:00.000001"),(77, "0000-12-28 01:00:00.999999"),(78, "0000-12-28 01:00:01.000000"),(79, "0000-12-28 01:00:01.000001"),
      (80, "0000-12-28 01:00:01.999999"),(81, "0000-12-28 01:00:59.000000"),(82, "0000-12-28 01:00:59.000001"),(83, "0000-12-28 01:00:59.999999"),(84, "0000-12-28 01:01:00.000000"),(85, "0000-12-28 01:01:00.000001"),(86, "0000-12-28 01:01:00.999999"),(87, "0000-12-28 01:01:01.000000"),(88, "0000-12-28 01:01:01.000001"),(89, "0000-12-28 01:01:01.999999"),(90, "0000-12-28 01:01:59.000000"),(91, "0000-12-28 01:01:59.000001"),(92, "0000-12-28 01:01:59.999999"),(93, "0000-12-28 01:59:00.000000"),(94, "0000-12-28 01:59:00.000001"),(95, "0000-12-28 01:59:00.999999"),(96, "0000-12-28 01:59:01.000000"),(97, "0000-12-28 01:59:01.000001"),(98, "0000-12-28 01:59:01.999999"),(99, "0000-12-28 01:59:59.000000"),
      (100, "0000-12-28 01:59:59.000001"),(101, "0000-12-28 01:59:59.999999"),(102, "0000-12-28 23:00:00.000000"),(103, "0000-12-28 23:00:00.000001"),(104, "0000-12-28 23:00:00.999999"),(105, "0000-12-28 23:00:01.000000"),(106, "0000-12-28 23:00:01.000001"),(107, "0000-12-28 23:00:01.999999"),(108, "0000-12-28 23:00:59.000000"),(109, "0000-12-28 23:00:59.000001"),(110, "0000-12-28 23:00:59.999999"),(111, "0000-12-28 23:01:00.000000"),(112, "0000-12-28 23:01:00.000001"),(113, "0000-12-28 23:01:00.999999"),(114, "0000-12-28 23:01:01.000000"),(115, "0000-12-28 23:01:01.000001"),(116, "0000-12-28 23:01:01.999999"),(117, "0000-12-28 23:01:59.000000"),(118, "0000-12-28 23:01:59.000001"),(119, "0000-12-28 23:01:59.999999"),
      (120, "0000-12-28 23:59:00.000000"),(121, "0000-12-28 23:59:00.000001"),(122, "0000-12-28 23:59:00.999999"),(123, "0000-12-28 23:59:01.000000"),(124, "0000-12-28 23:59:01.000001"),(125, "0000-12-28 23:59:01.999999"),(126, "0000-12-28 23:59:59.000000"),(127, "0000-12-28 23:59:59.000001"),(128, "0000-12-28 23:59:59.999999"),(129, "0001-01-01 00:00:00.000000"),(130, "0001-01-01 00:00:00.000001"),(131, "0001-01-01 00:00:00.999999"),(132, "0001-01-01 00:00:01.000000"),(133, "0001-01-01 00:00:01.000001"),(134, "0001-01-01 00:00:01.999999"),(135, "0001-01-01 00:00:59.000000"),(136, "0001-01-01 00:00:59.000001"),(137, "0001-01-01 00:00:59.999999"),(138, "0001-01-01 00:01:00.000000"),(139, "0001-01-01 00:01:00.000001"),
      (140, "0001-01-01 00:01:00.999999"),(141, "0001-01-01 00:01:01.000000"),(142, "0001-01-01 00:01:01.000001"),(143, "0001-01-01 00:01:01.999999"),(144, "0001-01-01 00:01:59.000000"),(145, "0001-01-01 00:01:59.000001"),(146, "0001-01-01 00:01:59.999999"),(147, "0001-01-01 00:59:00.000000"),(148, "0001-01-01 00:59:00.000001"),(149, "0001-01-01 00:59:00.999999"),(150, "0001-01-01 00:59:01.000000"),(151, "0001-01-01 00:59:01.000001"),(152, "0001-01-01 00:59:01.999999"),(153, "0001-01-01 00:59:59.000000"),(154, "0001-01-01 00:59:59.000001"),(155, "0001-01-01 00:59:59.999999"),(156, "0001-01-01 01:00:00.000000"),(157, "0001-01-01 01:00:00.000001"),(158, "0001-01-01 01:00:00.999999"),(159, "0001-01-01 01:00:01.000000"),
      (160, "0001-01-01 01:00:01.000001"),(161, "0001-01-01 01:00:01.999999"),(162, "0001-01-01 01:00:59.000000"),(163, "0001-01-01 01:00:59.000001"),(164, "0001-01-01 01:00:59.999999"),(165, "0001-01-01 01:01:00.000000"),(166, "0001-01-01 01:01:00.000001"),(167, "0001-01-01 01:01:00.999999"),(168, "0001-01-01 01:01:01.000000"),(169, "0001-01-01 01:01:01.000001"),(170, "0001-01-01 01:01:01.999999"),(171, "0001-01-01 01:01:59.000000"),(172, "0001-01-01 01:01:59.000001"),(173, "0001-01-01 01:01:59.999999"),(174, "0001-01-01 01:59:00.000000"),(175, "0001-01-01 01:59:00.000001"),(176, "0001-01-01 01:59:00.999999"),(177, "0001-01-01 01:59:01.000000"),(178, "0001-01-01 01:59:01.000001"),(179, "0001-01-01 01:59:01.999999"),
      (180, "0001-01-01 01:59:59.000000"),(181, "0001-01-01 01:59:59.000001"),(182, "0001-01-01 01:59:59.999999"),(183, "0001-01-01 23:00:00.000000"),(184, "0001-01-01 23:00:00.000001"),(185, "0001-01-01 23:00:00.999999"),(186, "0001-01-01 23:00:01.000000"),(187, "0001-01-01 23:00:01.000001"),(188, "0001-01-01 23:00:01.999999"),(189, "0001-01-01 23:00:59.000000"),(190, "0001-01-01 23:00:59.000001"),(191, "0001-01-01 23:00:59.999999"),(192, "0001-01-01 23:01:00.000000"),(193, "0001-01-01 23:01:00.000001"),(194, "0001-01-01 23:01:00.999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_datetimev2_6_part1_1_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_datetimev2_6_part1_1_not_nullable order by 1;'

}